import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:webview_flutter/webview_flutter.dart';

class ComWebViewDisplay extends StatefulWidget {
  const ComWebViewDisplay({super.key});

  @override
  State<ComWebViewDisplay> createState() => _ComWebViewDisplayState();
}

class _ComWebViewDisplayState extends State<ComWebViewDisplay> {
  late WebViewController controller;

  @override
  void initState() {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.landscapeLeft,
      DeviceOrientation.landscapeRight,
    ]);
    controller =
        WebViewController()
          ..setJavaScriptMode(JavaScriptMode.unrestricted)
          ..setNavigationDelegate(
            NavigationDelegate(
              onProgress: (progress) {
                print("加载$progress");
              },
              onPageStarted: (url) {},
              onPageFinished: (url) {},
              onHttpError: (error) {},
              onWebResourceError: (error) {},
              onNavigationRequest: (request) {
                return NavigationDecision.navigate;
              },
            ),
          )
          ..loadRequest(
            Uri.parse(
              'https://ygk.deman.cn/#/fullscreen/preview1?id=15&stationCode=ZF20230421001&customerId=2386',
            ),
          );
    super.initState();
  }

  @override
  void dispose() {
    controller.clearCache();
    controller.clearLocalStorage();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(body: WebViewWidget(controller: controller));
  }
}
